/*
 * @Author: your name
 * @Date: 2024-05-30 11:42:12
 * @LastEditTime: 2024-05-30 11:47:23
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \.leetcode\860.柠檬水找零.cpp
 */
/*
 * @lc app=leetcode.cn id=860 lang=cpp
 *
 * [860] 柠檬水找零
 */

// @lc code=start
class Solution {
public:
    bool lemonadeChange(vector<int>& bills) {
        int five =0, ten = 0, twenty = 0;
        for(auto bill:bills){
            if(bill == 5){
                five++;
            }
            else if(bill == 10){
                five--;
                if(five < 0){
                    return false;
                }
                ten++;
            }
            else{
                if(ten > 0 && five >0){
                    ten--;
                    five--;
                }else if(five >= 3){
                    five-=3;
                }else{
                    return false;
                }
            }
        }
        return true;
    }
};
// @lc code=end

